<?php

namespace App\Http\Middleware;

use App\Exceptions\common\api\SystemCode;
use App\Exceptions\common\api\SystemMessage;
use App\Exceptions\CustomException;
use Closure;
use Illuminate\Http\Request;
use Exception;

class AuthCheck
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        //var_dump(2222);
        if (empty($request->userId) || empty($request->userInfo)) {
            throw new CustomException([
                    'code'=>SystemCode::SYSTEM_ERROR_LOGIN_EXPIRES,
                    'msg'=>SystemMessage::SYSTEM_ERROR_LOGIN_EXPIRES
                ]);
        }
        return $next($request);
    }
}
